import 'package:baseProjectFlutter/config/theme.dart';
import 'package:baseProjectFlutter/page/view/unknown_page.dart';
import 'package:baseProjectFlutter/router/app_routes_manager.dart';
import 'package:baseProjectFlutter/utils/app_utils.dart';
import 'package:baseProjectFlutter/utils/common/window_config.dart';
import 'package:baseProjectFlutter/utils/lifecycle/lifecycle.dart';
import 'package:baseProjectFlutter/utils/store_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import 'config/app_glabol.dart';
import 'config/i18n/i18n.dart';

void main() async {
  await WindowConfig.init();

  //获取设备信息
  await AppUtils.init();
  //初始化路由
  AppRoutes.init();
  await StoreUtils.init();

  runApp(
    MyApp(),
  );
}

class MyApp extends StatelessWidget {
  final themeVm = Get.put(ThemeVm());

  MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    AppGlabol.initScreenSize(context);
    return Obx(() {
      return GetMaterialApp(
        getPages: AppRoutes.routes,
        initialRoute: AppRouteKey.root,
        navigatorKey: AppRoutes.navigatorKey,
        navigatorObservers: [PageLifecycleObserver()],
        unknownRoute: GetPage(
          name: AppRouteKey.unknown,
          page: () => const UnknownPage(),
        ),
        // 你的翻译
        translations: I18nConfig(),
        // 将会按照此处指定的语言翻译
        // locale: const Locale('zh', 'CN'),
        locale: const Locale('en', 'US'),
        // 添加一个回调语言选项，以备上面指定的语言翻译不存在
        fallbackLocale: const Locale('zh', 'CN'),
        title: 'VinkaService',
        theme: lightTheme,
        darkTheme: darkTheme,
        themeMode: themeVm.themeMode,
        builder: FlutterSmartDialog.init(),
      );
    });
  }
}
